#include <iostream>
using namespace std;

int main2() {
	int n ,p= 0;
	cin >> n;
	
	while (n != 0) {
		int* a = (int*)malloc(sizeof(int) * n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		cin >> p;
		int* b = (int*)malloc(sizeof(int) * p);

		for (int i = 0; i < p; i++) {
			b[i] = a[i];
			//a[i] = a[i + p];`
		}
	
		for (int i = 0; i < n-p; i++) {	
		a[i] = a[i + p];
			
		}

		for (int i = n - p,k=0; i < n ; i++,k++) {
			a[i] =  b[k];

		}


		for (int i = 0; i < n-1; i++) {
		
			cout << a[i] << " ";
		}
		cout << a[n - 1] << endl;
		//cout << endl;
		cin >> n;
		return 0;
		
	}
}